<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
		xmlns:h="http://java.sun.com/jsf/html"  
		xmlns:f="http://java.sun.com/jsf/core"
		xmlns:ui="http://java.sun.com/jsf/facelets"
		xmlns:c="http://java.sun.com/jsp/jstl/core"
        xmlns:a4j="http://richfaces.org/a4j"
        xmlns:rich="http://richfaces.org/rich"> 
    
    <ui:composition template="#{helperNavigation.getPathTemplate('administration')}">
        <ui:define name="pageTitle">Gestion des commandes</ui:define>
        <ui:define name="mainTitle">Gestion des commandes</ui:define>
        <ui:define name="mainContent">
            <rich:dataTable value="#{orderManager.setAllOrdersAdmin()}" var="order" rows="10" rowClasses="odd-row, even-row" style="width: 100%;">
                    <f:facet name="header">
                        <rich:columnGroup>
                            <rich:column colspan="1">
                                <h:outputText value="Commande" />
                            </rich:column>
                            <rich:column colspan="1">
                                <h:outputText value="Détails de la commande" />
                            </rich:column>
                        </rich:columnGroup>
                    </f:facet>

                    <!-- Left column -->
                    <rich:column>
                        <h:form class="form-inline center">
                            <h4 class="blue">Commande n°#{order.id}</h4><br />
                            <b class="blue">Date de commande :</b> <h:outputText value="#{order.orderDate}"><f:convertDateTime pattern="dd/MM/YYYY" /></h:outputText><br />
                            <b class="blue">État :</b> #{order.state}<br /><br />
                            <b class="blue">Etat : <h:selectOneMenu valueChangeListener="#{orderManager.change}" value="#{order.state}" ><f:selectItems value="#{orderManager.states}"/><f:param value="#{order.state}"/></h:selectOneMenu></b>
                            <h:commandButton value="Valider" action="#{orderManager.updateOrderState(order.id)}" styleClass="btn btn-primary" />
                            <br />
                       </h:form>
                    </rich:column>

                    <!-- Right column -->
                    <rich:column>
                        <rich:dataTable value="#{order.invoices}" var="invoice" rows="0" rowClasses="odd-row, even-row" style="width: 100%;">
                            <f:facet name="header">
                                <rich:columnGroup>
                                    <rich:column>
                                        <h:outputText value="Titre" />
                                    </rich:column>
                                    <rich:column>
                                        <h:outputText value="Quantité" />
                                    </rich:column>
                                    <rich:column>
                                        <h:outputText value="Prix unitaire" />
                                    </rich:column>
                                    <rich:column>
                                        <h:outputText value="Prix total" />
                                    </rich:column>
                                </rich:columnGroup>
                            </f:facet>

                            <rich:column>
                                <h:outputText value="#{invoice.book.title}" />
                            </rich:column>
                            <rich:column>
                                <h:outputText value="#{invoice.quantity}" />
                            </rich:column>
                            <rich:column>
                                <h:outputText value="#{invoice.book.price} €" />
                            </rich:column>
                            <rich:column>
                                <h:outputText value="#{invoice.book.price * invoice.quantity} €" />
                            </rich:column>

                            <f:facet name="footer">
                                <rich:columnGroup>
                                    <rich:column colspan="3"></rich:column>
                                    <rich:column colspan="1" >Prix total :&nbsp;&nbsp;<h:outputText value="#{orderManager.getTotalPrice(order)} €" styleClass="label"></h:outputText></rich:column>
                                </rich:columnGroup>
                            </f:facet>
                            <br />
                        </rich:dataTable>
                    </rich:column>
                </rich:dataTable>
            
        </ui:define>
    </ui:composition>
</html>

